from matplotlib import pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# Constants.
r1 = 1.496
r2 = 2.279
o = (r1 - r2) / 2
a = (r1 + r2) / 2
b = a / 1.1

x1 = np.linspace(-r1, r1, num=100)
y1 = np.sqrt(r1**2-x1**2)
x2 = np.linspace(-r2, r2, num=100)
y2 = np.sqrt(r2**2-x2**2)
x3 = np.linspace(o-a, o+a, num=100)
y3 = b * np.sqrt(1 - (x3-o)**2 / a**2)

plt.title('霍曼转移过程图')
plt.arrow(-1.5*r2, 0, 3*r2, 0, color='black',
          head_length=0.2, head_width=0.1)
plt.arrow(0, -1.5*r2, 0, 3*r2, color='black',
          head_length=0.2, head_width=0.1)
plt.axis('off')
plt.axis('equal')

plt.plot(x1, y1, color='lightskyblue', label='地球公转轨道')
plt.plot(x1, -y1, color='lightskyblue')
plt.plot(x2, y2, color='red', label='火星公转轨道')
plt.plot(x2, -y2, color='red')
plt.plot(x3, y3, color='gold', label='霍曼转移轨道')
# plt.plot(x3, -y3, color='gold')

plt.legend()
plt.show()
